﻿using StrokeCenterSystem.Bll;
using StrokeCenterSystem.Core;
using StrokeCenterSystem.Model;
using StrokeCenterSystem.ThreeCenterManage;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Common;
using StrokeCenterSystem.Utils;

namespace StrokeCenterSystem.Areas.StrokeCenter.Controllers
{
    public class MedicalRecordsController : BaseController
    {
        // GET: /StrokeCenter/MedicalRecords/

        public ActionResult Index()
        {
            string patientId = Request.QueryString["patientId"];
            ViewBag.patientId = patientId;
            int review = WebUtils.GetInt("review");
            ViewBag.Review = review;
            return View();
        }
        /// <summary>
        /// 根据患者查询卒中类型
        /// </summary>
        /// <returns></returns>
        public ActionResult GetStrokeDiagnosis()
        {
            string Patient_ID = Request["txtID"];
            OperateResult result = MedicalRecordsManager.Get_StrokeDiagnosis(Patient_ID);
            return JsonDate(result);
        }

        #region ceacas
        public ActionResult Ceacasmr()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        public ActionResult CeacasmrPrint()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        /// <summary>
        /// 获取ceacas病历数据
        /// </summary>
        /// <param name="patientid"></param>
        /// <returns></returns>
        public ActionResult GetCEACAS(string patientid)
        {
            OperateResult resultInfo = MedicalRecordsManager.Get_CEACAS(patientid);
            if (resultInfo.Result != 1) return Content(resultInfo.Body.ToString());
            string json = resultInfo.Body.ToString();
            StrokeCenterSystem.Model.GetCEACAS PatHis = JsonConvert.DeserializeObject<GetCEACAS>(json);
            return JsonDate(PatHis);
        }
        public ActionResult SaveCeacasmr(string datajson = "")
        {
            OperateResult result = new OperateResult();
            if (!string.IsNullOrEmpty(datajson))
                result = MedicalRecordsManager.Set_CEACAS(datajson);
            return JsonDate(result);
        }
        #endregion

        #region 静脉溶栓血管内介入
        public ActionResult Jmrsxgnjrzlmr()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        public ActionResult JmrsxgnjrzlmrPrint()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        /// <summary>
        /// 获取静脉溶栓血管内介入病历数据
        /// </summary>
        /// <param name="patientid"></param>
        /// <returns></returns>
        public ActionResult Get_IntravenousThrombolysis(string patientid)
        {
            OperateResult resultInfo = MedicalRecordsManager.Get_IntravenousThrombolysis(patientid);
            if (resultInfo.Result != 1) return Content(resultInfo.Body.ToString());
            string json = resultInfo.Body.ToString();
            StrokeCenterSystem.Model.GetAIS PatHis = JsonConvert.DeserializeObject<GetAIS>(json);
            return JsonDate(PatHis);
        }
        public ActionResult Set_IntravenousThrombolysis(string datajson = "")
        {
            OperateResult result = new OperateResult();
            if (!string.IsNullOrEmpty(datajson))
                result = MedicalRecordsManager.Set_IntravenousThrombolysis(datajson);
            return JsonDate(result);
        }
        #endregion

        #region 脑出血
        public ActionResult Ncxmr()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        public ActionResult NcxmrPrint()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        /// <summary>
        /// 获取脑出血病历数据
        /// </summary>
        /// <param name="patientid"></param>
        /// <returns></returns>
        public ActionResult Get_Cerebralhemorrhage(string patientid)
        {
            OperateResult resultInfo = MedicalRecordsManager.Get_Cerebralhemorrhage(patientid);
            if (resultInfo.Result != 1) return Content(resultInfo.Body.ToString());
            string json = resultInfo.Body.ToString();
            StrokeCenterSystem.Model.GetCHMR PatHis = JsonConvert.DeserializeObject<GetCHMR>(json);
            return JsonDate(PatHis);
        }
        public ActionResult SaveNcxmr(string datajson = "")
        {
            OperateResult result = new OperateResult();
            if (!string.IsNullOrEmpty(datajson))
                result = MedicalRecordsManager.Set_Cerebralhemorrhage(datajson);
            return JsonDate(result);
        }
        #endregion

        #region 颅内动脉瘤
        public ActionResult Lndmlmr()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        public ActionResult LndmlmrPrint()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }
        /// <summary>
        /// 获取颅内动脉瘤病历数据
        /// </summary>
        /// <param name="patientid"></param>
        /// <returns></returns>
        public ActionResult Get_IntracranialAneurysm(string patientid)
        {
            OperateResult resultInfo = MedicalRecordsManager.Get_IntracranialAneurysm(patientid);
            if (resultInfo.Result != 1) return Content(resultInfo.Body.ToString());
            string json = resultInfo.Body.ToString();
            StrokeCenterSystem.Model.GetIAMR PatHis = JsonConvert.DeserializeObject<GetIAMR>(json);
            return JsonDate(PatHis);
        }
        public ActionResult SaveLndmlmr(string datajson = "")
        {
            OperateResult result = new OperateResult();
            if (!string.IsNullOrEmpty(datajson))
                result = MedicalRecordsManager.Set_IntracranialAneurysm(datajson);
            return JsonDate(result);
        }
        #endregion

        #region 卒中时间路径
        public ActionResult Timeline()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.patientId = pid;
            return View();
        }

        public ActionResult TimeLinePrint()
        {
            return View();
        }
        /// <summary>
        /// 获取卒中时间路径数据
        /// </summary>
        /// <param name="patientid"></param>
        /// <returns></returns>
        public ActionResult Get_PatientTimePath(string patientid)
        {
            OperateResult resultInfo = MedicalRecordsManager.Get_PatientTimePath(patientid);
            if (resultInfo.Result != 1) return Content(resultInfo.Body.ToString());
            string json = resultInfo.Body.ToString();
            StrokeCenterSystem.Model.GetTimePath PatHis = JsonConvert.DeserializeObject<GetTimePath>(json);
            return JsonDate(PatHis);
        }
        /// <summary>
        /// 保存卒中时间路径数据
        /// </summary>
        /// <param name="datajson"></param>
        /// <returns></returns>
        public ActionResult SetExecutionDate(string datajson = "")
        {
            OperateResult result = new OperateResult();
            if (!string.IsNullOrEmpty(datajson))
                result = MedicalRecordsManager.Set_ExecutionDate(datajson);
            return JsonDate(result);
        }
        #endregion

        #region 通用病历

        public ActionResult Commonmr()
        {
            string pid = WebUtils.GetString("pid");
            ViewBag.PatientId = pid;
            return View();
        }

        /// <summary>
        /// 获取通用病历
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public ActionResult GetPatinet_BaseInfor(string patientId)
        {
            OperateResult resultInfo = MedicalRecordsManager.GetPatinet_BaseInfor(patientId);
            return JsonDate(resultInfo);
        }

        /// <summary>
        /// 保存通用病历
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public ActionResult SetPatinet_BaseInfor(string datajson = "")
        {
            OperateResult resultInfo = MedicalRecordsManager.SetPatinet_BaseInfor(datajson);
            return JsonDate(resultInfo);
        }

        #endregion

        /// <summary>
        /// 审核
        /// </summary>
        /// <returns></returns>
        public ActionResult Review()
        {
            return View();
        }

        /// <summary>
        /// 保存审核信息
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="state"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public ActionResult ReviewSave(string pid, int state, string message)
        {
            OperateResult resultInfo = MedicalRecordsManager.ReviewSave(pid, state, message, loginUser.Name);
            return JsonDate(resultInfo);
        }
    }
}
